#!/usr/bin/env python
# -*- coding: utf-8 -*-

import unittest
import os
import subprocess

import wc
class Testwc(unittest.TestCase):
    def __init__(self, test_name):

        def test_func():
            file_handle = open('testcases/%s'%(test_name), "r");
            nline, nword, nchar = list(wc.count(file_handle))
            file_handle.seek(0)
            correct = subprocess.check_output("wc",
                                              stdin = file_handle);
            self.assertRegexpMatches(correct,
                                     "%d\\s+%d\\s+%d\\s+"%(nline,nword,nchar))
            file_handle.close()

        setattr(self, test_name, test_func)
        super(Testwc, self).__init__(test_name);

    def setUp(self):
        pass


if __name__ == '__main__':
    testcases = [Testwc(f) for f in os.listdir('testcases')]
    suite = unittest.TestSuite(testcases)
    unittest.TextTestRunner(verbosity=3).run(suite)
